import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class Main {

    // public static BlockingQueue<String> queue = new LinkedBlockingQueue();
    public static void main(String[] args) {
        BlockingQueue<Integer> queue =
                new LinkedBlockingQueue<>();
        Thread thread1 = new Thread(()->{
            int value = 0;
            while (true) {
                try {
                    System.out.println("生成元素" + value);
                    queue.put(value);
                    value++;
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Thread thread2 = new Thread(()-> {
           while (true) {
               try {
                   int result = queue.take();
                   System.out.println("消费元素" + result);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });

        thread1.start();
        thread2.start();
    }


    public static void main1(String[] args) throws InterruptedException {
        BlockingQueue<String> blockingQueue =
                new LinkedBlockingQueue<>();
        blockingQueue.take();
    }
}
